#include "common.h"

layout(location = TEXCOORD0) in vec2 Tex0;
layout(location = TEXCOORD1) in vec2 Tex1;
layout(location = TEXCOORD2) in vec2 Tex2;
layout(location = TEXCOORD3) in vec2 Tex3;
layout(location = TEXCOORD4) in vec4 vColor;

layout(location = COLOR0) out vec4 oColor;

//////////////////////////////////////////////////////////////////////////////////////////
#define	LUMINANCE_BASE		0.0001f

half	luminance	(float2	tc)	
{
	half3	source 	= tex2D(s_image,tc).rgb;
	return 	dot( source, LUMINANCE_VECTOR*def_hdr );
}
//////////////////////////////////////////////////////////////////////////////////////////
// 	perform 2x2=4s convolution, working on 4x4=16p area
//	that means 256x256 source will be scaled to (256/4)x(256/4) = 64x64p
//	a):	256x256 => 64x64p	with log 
//	b):	64x64p	=> 8x8p
//	c):	8x8p	=> 1x1p		with exp
void main()
{
	// first 8 bilinear samples (8x4 = 32 pixels)
	half4 	final;
		final.x =	luminance(Tex0.xy);
		final.y = 	luminance(Tex1.xy);
		final.z = 	luminance(Tex2.xy);
		final.w =	luminance(Tex3.xy);

	// OK
	oColor		=	final;
}
